package com.dyz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dyz.domain.DTO.WebConfigDTO;
import com.dyz.domain.WebConfig;
import com.dyz.model.Result;
import com.dyz.service.IWebConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/webConfig")
@Api(tags = "网站配置管理")
public class WebConfigController {
    @Resource
    private IWebConfigService webConfigService;
    @GetMapping("/getList")
    @ApiOperation(value = "获取列表")
    @PreAuthorize("hasAuthority('web_config_query')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页显示条数"),
    })
    public Result<?> getWebConfigList(@ApiIgnore Page<WebConfig> page, String name, String type) {
        return webConfigService.getConfigList(page,name,type);
    }
    @GetMapping("/getOneObj/{id}")
    @ApiOperation(value = "获取对象")
    @PreAuthorize("hasAuthority('web_config_query')")
    public Result<?> getOneObj(@PathVariable Long id) {
        return webConfigService.getOneObj(id);
    }
    @PostMapping("/create")
    @ApiOperation(value = "创建网站信息配置")
    @PreAuthorize("hasAuthority('web_config_create')")
    public Result<?> create(@RequestBody WebConfig webConfig) {
        return webConfigService.save(webConfig)?  Result.success("创建成功") : Result.fail("创建失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "更新网站信息配置")
    @PreAuthorize("hasAuthority('web_config_update')")
    public Result<?> update(@RequestBody WebConfig webConfig) {
        return webConfigService.updateById(webConfig)? Result.success("更新成功") : Result.fail("更新失败");
    }
    @PostMapping("/delete")
    @ApiOperation(value = "删除网站信息配置")
    @PreAuthorize("hasAuthority('web_config_delete')")
    public Result<?> delete(@RequestBody String[] ids) {
        return webConfigService.delete(ids);
    }
}
